/**
 * 初始化时处理
 */
let dateStr
$(function ready() {
    // 获取当天日期
    let now = new Date();
    let year = now.getFullYear();
    let month = (now.getMonth() + 1) < 10 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1);
    let date = now.getDate() < 10 ? "0" + (now.getDate()) : (now.getDate());
    dateStr = year + month + date + "";
    // 设置四个元素的占位符为当前日期字符串
    $("#jdDateStr").attr("placeholder", dateStr);
    $("#mtDateStr").attr("placeholder", dateStr);
    $("#pddDateStr").attr("placeholder", dateStr);
    $("#xxDateStr").attr("placeholder", dateStr);
});

/**
 * 京东 生成导入文件 按钮点击事件
 */
$("#jdExport").click(function () {
    writeExpressImport("jd", $("#jdExpress").val(), $("#jdDateStr").val(), $("#jdPassword").val())
});

/**
 * 京东 生成导入文件 按钮点击事件
 */
$("#mtExport").click(function () {
    writeExpressImport("mt", $("#mtExpress").val(), $("#mtDateStr").val(), $("#mtPassword").val())
})

/**
 * 根据 店铺导出文件 生成 快递导入文件
 */
function writeExpressImport(shop, express, exportDateStr, password) {
    if (exportDateStr.trim() == '') {
        exportDateStr = dateStr;
    }
    $.get({
        url: "/file/writeExpressImport/" + shop + "/" + express,
        data: {
            "dateStr": exportDateStr,
            "password": password,
        },
        success: function (result) {
            layerShow(result);
        }
    });
}


$("#jdSend").click(function (){
    importOrder("jd", $("#jdExpress").val(), $("#jdDateStr").val())
});
$("#mtSend").click(function (){

    importOrder("mt", $("#mtExpress").val(), $("#mtDateStr").val())
});
$("#pddSend").click(function (){

    importOrder("jd", $("#pddExpress").val(), $("#pddDateStr").val())
});
$("#xxSend").click(function (){

    importOrder("jd", $("#xxExpress").val(), $("#xxDateStr").val())
});

/**
 * 韵达国际 订单导入到系统
 */
function importOrder(shop, express, exportDateStr) {
    if (exportDateStr.trim() == '') {
        exportDateStr = dateStr;
    }

    $.get({
        url: "/file/importOrder/" + shop + "/" + express,
        data: {
            "dateStr": exportDateStr,
        },
        success: function (result) {
            layerShow(result);
        }
    });
}

/**
 * 圆通国际 订单导入到系统
 */
function ytgjSendOnClick() {
    $.get({
        url: "/ytgj/writeSendExcel/",
        data: {
            dateStr: $("#ytgjSendDate").val()
        },
        success: function (result) {
            layerShow(result);
        }
    });
}



/**
 * 侧边栏切换元素时，颜色变化和主页面的变化
 */
function switchPage() {
    $("#navFrame").attr("src", $(this).data("src"));
    $("#left-nav li").css("background-color", "white");
    $("#left-nav li a").css("color", "black");
    $(this).parent().css("background-color", "black");
    $(this).css("color", "white");
}


